package com.kaduoxee.ebooks.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kaduoxee.ebooks.entity.Bookshelf;
import com.kaduoxee.ebooks.mapper.BookshelfMapper;
import com.kaduoxee.ebooks.service.BookshelfService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

@Service
public class BookshelfServiceImpl extends ServiceImpl<BookshelfMapper, Bookshelf>
        implements BookshelfService {

    /**
     * 判断指定user书架上是否包含某本小说
     * 有-->true
     * 无-->false
     */

    public boolean hasFiction(Integer userId,Integer fictionId) {
        QueryWrapper<Bookshelf> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id", userId);
        List<Bookshelf> books = list(wrapper);

        for (Bookshelf book : books) {
            if (Objects.equals(book.getFictionId(), fictionId)) return true;
        }

        return false;
    }
}
